#include<stdio.h>
#include<stdlib.h>
typedef struct stu
{
      int sex;
      char name[9];
}s;
int main()
{
    int N;
    int i;
    s *xs,*xs0,*xs1;
    s *p,*f1,*f2;
    scanf("%d",&N);
    xs=(s*)malloc(N*sizeof(s));
    xs0=(s*)malloc(N/2*sizeof(s));
    xs1=(s*)malloc(N/2*sizeof(s));
    if(xs==NULL||xs0==NULL||xs1==NULL)
    {
        printf("空间不足!");
        exit(1);
    }
    f1=xs0;f2=xs1;
    for(i=0,p=xs;i<N;i++,p++)
    {
        scanf("%d%s",&p->sex,p->name);
        if(p->sex==0)
            *(f1++)=*p;
        else
            *(f2++)=*p;        
    }
    for(i=0,p=xs,f1=xs1+N/2-1,f2=xs0+N/2-1;i<N/2;i++,p++)
    {
        if(p->sex==0)
            printf("%s %s\n",p->name,(f1--)->name);
        else
            printf("%s %s\n",p->name,(f2--)->name);
    }
    free(xs);xs=NULL;free(xs0);xs0=NULL;free(xs1);xs1=NULL;
    return 0;
}